﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace DelaerPlatform.Core.Repository
{
    public static class LinqExtension
    {
        public async static IAsyncEnumerable<TEntity> WhereAsync<TEntity>(this DbSet<TEntity> dbSet, Func<TEntity, bool> predicate)
            where TEntity : class
        {
            var res = dbSet.Where(predicate);
            foreach (var entity in res)
            {
                yield return entity;
            }
        }

        public  async static Task<List<TEntity>> ToListAsync<TEntity>(this IAsyncEnumerable<TEntity> entities)
        {
            List<TEntity> ls=new List<TEntity>();
            await foreach (var item in entities)
            {
                ls.Add(item);
            }
            return ls;
        }
     }
}
